<template>
 <view :style="{height:getstatusheight()+`px`}"></view>
 <view :style="{height:gettitleheight()+`px`}"></view>
 <view class="con">
	   <view class="top">
		    <view class="tt">
				你好,<br/>
				欢迎来到校园点餐
			</view>
			<view class="logo">
				  <image src="../../static/logo-tm.png" mode="aspectFill"></image>
				  <view class="">兮沒</view>
			</view>
			<view class="button">
				<view class="t">保证你的信息安全</view>
				<view class="b" @click="wxlogin"><view class="iconfont icon-552cd5c76f532"></view> 微信一键登录</view>
			</view>
			<view class="go">
				  <view class="l" @click="codelogin">验证码登录</view>
				  <view class="r" @click="gousernamelogin">账号密码登录</view>
			</view> 
	   </view>
	   <view class="bottom">使用微信一键登录即代表您已同意 <text class="blue">《兮沒账号认证服务条款》</text> 和<text class="blue">《用户协议</text>》、<text class="blue">《启私政策》</text>并使用本机号码登录</view>
 </view>
 <uni-popup ref="popup" type="bottom">
	 <view class="popbox"  v-if="userinfo">
		   <view class="tit" space="emsp"><image src="../../static/logo.png" mode="aspectFill"></image>兮沒快餐 申请</view>
		   <view class="conss">获取你昵称、头像、地区以及性别</view>
		   <view class="info">
			   <image :src="userinfo.avatarUrl" mode="aspectFill"></image>
			   <view class="r">
				     <view class="t">{{userinfo.nickName}}</view>
					 <view class="b">微信个人信息</view>
			   </view>
		   </view>
		   <view class="bottom">
		   	    <view class="l" @click="qx">拒绝</view>
		   	    <view class="r" @click="login">允许</view>
		   </view>
	 </view>
 </uni-popup>
</template>

<script setup>
	import {onLoad} from '@dcloudio/uni-app'
	import {getwxlogin} from '@/api/index.js'
	import {nextTick, ref} from 'vue'
	import userstrore from '@/store/user.js'
	const useuserstrore=userstrore()
	const popup=ref()
	const userinfo=ref()
		import {getstatusheight,gettitleheight} from '@/util/getsysinfo.js'
		const conheight=getstatusheight()+gettitleheight()+'px'
		const gousernamelogin=()=>{
			 uni.navigateTo({
			 	url:"/pages/usernamelogin/usernamelogin"
			 })
		}
		const qx=()=>{
			popup.value.close()
		}
		const login=()=>{
			 uni.login({
			 	provider:"weixin",
				success(e) {
					snddata(e.code)
				}
			 })
		}
		const snddata=async(code)=>{
			const data={
			...userinfo.value,
			code
			}
			const rudata=await getwxlogin(data)
			if(rudata.code==200){
				useuserstrore.userinfo=rudata.data
				useuserstrore.token=rudata.token
				uni.showToast({
					title:"登陆成功!",
					icon:"none"
				})                
				setTimeout(()=>{
					uni.reLaunch({
						url:"/pages/index/index"
					})
				},2000) 
			}
		}
		const wxlogin=()=>{
			uni.getUserProfile({
				desc:"登录",   
				success(e) {
					userinfo.value=e.userInfo
					popup.value.open()
				},
				fail(e) {
					console.log(e)
				}
			})
		}
		const codelogin=()=>{
			uni.navigateTo({
				url:"/pages/phonecodelogin/phonecodelogin"
			})
		}
		
</script>

<style lang="scss" scoped>
	.blue{
		color: #6491f8;
	}
	.con{
		width: 100%;
		height:calc(100vh - v-bind(conheight));
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		align-items: center;
		.top{
			width: 100%;
			padding: 0 50rpx;
		}
		.tt{
			height: fit-content;
			width: 100%;
			text-align: start;
			font-size: 45rpx;
			font-weight: 700;
			line-height: 70rpx;
		}
		.logo{
			margin-top: 30rpx;
			height: 500rpx;
			width: 100%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			gap: 50rpx;
			font-weight: 700;
			image{
				height: 100rpx;
				width: 350rpx;
			}
		}
		.button{
			height:130rpx;
			width: 100%;
			display: flex;
			flex-direction: column;
			margin-top: 30rpx;
			padding: 0 20rpx;
			.t{
				font-size: 20rpx;
				color: #aaa;
				height: 30rpx;
				margin:0 0  10rpx 10rpx;
			}
			.b{
				height: 100rpx;
				background-color: #23d96e;
				border-radius: 110rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
				font-size: 30rpx;
				gap: 20rpx;
				.iconfont{
					font-size: 40rpx;
				}
			}
		}
	    .go{
			margin-top: 20rpx;
			width: 100%;
			display: flex;
			justify-content: space-between;
			padding: 0 30rpx;
			font-size: 23rpx;
			color: #6491f8;
		}
	}
	.bottom{
		font-size: 22rpx;padding: 0 50rpx;
		line-height: 35rpx;
	}
	.popbox{
		height: 35vh;
		background-color: #fff;
		border-radius: 15rpx;
		padding: 0 50rpx;
		.tit{
			font-size: 25rpx;
            height: 100rpx;
			display: flex;
			align-items: center;
			image{
				height: 30rpx;
				width: 30rpx;
				margin-right: 10rpx;
				border-radius: 50%;
			}
		}
		.conss{
			font-size: 30rpx;
			font-weight: 700;
			margin-bottom: 40rpx;
		}
		.info{
			height: 150rpx;
			border-top: 1rpx solid #eee;
			border-bottom: 1rpx solid #eee;
			padding: 5rpx 0;
			display: flex;
			align-items: center;
			image{
				width: 85rpx;
				height: 85rpx;
				border-radius: 10rpx;
				margin-right:20rpx ;
			}
			.r{
				width: 500rpx;
				height: 100%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				gap: 10rpx;
				font-size: 22rpx;
				.t{
					font-size: 32rpx;
				}
				.b{
					color: #7b7b7b;
				}
			}
		}
		.bottom{
			margin-top: 100rpx;
			display: flex;
			align-items: center;
			justify-content: space-around;
			gap: 20rpx;
			view{
				height: 80rpx;
				width: 35%;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 25rpx;
			}
			.l{
				background-color: #f2f2f2;
				color: #23d96e;
			}
			.r{
				background-color: #23d96e;
				color: #fff;
			}
		}
	}
</style>
